In-memory mechanical computing

Mechanical computing requires matter to adapt behavior according to retained knowledge, often through integrated sensing, actuation, and control of deformation. However, inefficient access to mechanical memory and signal propagation limit mechanical computing modules. To overcome this, we developed an in-memory mechanical computing architecture where computing occurs within the interaction network of mechanical memory units. Interactions embedded within data read-write interfaces provided function-complete and neuromorphic computing while reducing data traffic and simplifying data exchange. A reprogrammable mechanical binary neural network and a mechanical self-learning perceptron were demonstrated experimentally in 3D printed mechanical computers, as were all 16 logic gates and truth-table entries that are possible with two inputs and one output. The in-memory mechanical computing architecture enables the design and fabrication of intelligent mechanical systems.


Supplementary Note 1: Additional computing process of the mechanical XNOR structure
In the main text, the computing process of the mechanical XNOR structure has been introduced for the input being (0, 0) and (1, 0). Note that the computing process for the input being (0, 1) is the same as that of (1, 0) owing to the upper-bottom symmetry of the design structure. Here, we will only discuss the state change when the input is (1,1), as shown in Supplementary Figure 1. If the input is (1, 1), the two input buckled beams compress the two spring 1 simultaneously (Supplementary Figure 1a). Considering that the geometry of the input buckled beams is the same, the compressive force at both ends of the balance bar 1 is also the same, and balance bar 1 remains vertical. Thus, the slider bars and links stay at their initial position. When the structure is subject to a time signal (external force F), the common vertex of the two link 1 will push the output buckled beam for a distance of  (Supplementary Figure 1b). Driven by link 2 and link 3, two of the balance bar 2 rotate and touch the slider bars. The right ends of spring 1 are also pushed for a distance of   and the input buckled beams are initialized to state 0. Considering the output buckled beam arching to the right, its state will switch to 1 after the force F is released, i.e., the structure outputs 1 when the inputs are (1, 1).

Supplementary Note 2: Assembling of the basic mechanical interaction structures
The assembling details of the basic mechanical interaction structures are shown in Thus, the computing can be done as shown in Fig. 2.
Thus, slider 1 can only move translationally along the x direction while link 2 and slider block 2 can only move translationally along the y direction. The balance bar 1 and 2 (marked in Fig. 3) are connected to the support via cylinder 1 and 2. They can only rotate around these cylinders. Besides, the slider block marked in Fig. 3 is connected to link 2 by the insert block. It follows the motion of link 2.
The assembling details of the mechanical perceptron structure are shown in Supplementary Figure 3d. Slider block 1, 2, and 3 are fixed into the slider groove 1, 2, and 3, respectively. All these slider blocks can only move translationally along the y direction.

Supplementary Note 3: Design of other structures required for computing
Designs of several other typical structures required to facilitate computing are given in while the output is defined as the movement of the block at the right of the input bars ( Supplementary Figure 4ciii and civ). If c =0, block 2 will block the movement of input bar 2, thus the output will be In1 (Supplementary Figure 4ciii). As for c =1, the movement of input bar 1 will be blocked by block 1, thus the output will be In2 (Supplementary Figure 4civ). Thereby, the structure fulfills the requirements of a data selector mentioned in Fig. 5b.

 
tanh  which is also used for activation. In doing so, a relaxed version of the corresponding BNN is obtained and trained. In the second round, the weight and bias in the first round are binarized to initialize the BNN parameters. A noisy feed-forward step is followed, and the parameters are updated while letting the network be aware of the additional error introduced by the binarization procedure. By repeating these two rounds, the BNN is trained.
To verify the training method, a BNN is trained to distinguish between labeled images of handwritten digits. 50 images of each digit from the MINST database (Ref 44) are picked randomly as the training set while additional 50 images of each digit serve as the testing set. Each image is represented by an array containing integers ranging from 0 to 255. We rewrite the integers larger (smaller) than 255/2 as 1 (-1) and reduce the image to a 14×14 array with a pooling process before training. The corresponding handwritten digit is shown as the insert of Fig. 4g. Then, a BNN with 196 input nodes, 14 hidden nodes, and 1 output node is trained. The output 3 1 x is desired to be -1 (1) when the input handwritten digit is 0 (1). The training process is shown in Fig. 4g. The error means the number of handwritten digits failed to be distinguished in the training set (or testing set). The errors for the training and testing sets gradually reduce and become 1 after about 170 training steps. Considering the equivalence of the BNN and MBNN mentioned in the main text, the training method can serve as a strong tool to design intelligent deformation input-output relationships that can even adapt to unseen conditions by its ability of generalization.
Except for the MBNN shown in the main text, we have also constructed an MBNN with different network structures. An example is shown in Supplementary Figure 5a where y is the output, i x is the input, i w is the weight, B i x  and R i w  , i =0, 1, 2,…, n . The weights of the backward propagation are updated as: where t y is the target output, and dw  is the updating increment. The corresponding mechanical self-learning perceptron model is shown in Supplementary Figure 6B. Its forward propagation procedure represented by the black interaction symbols is the same as Eq.
(1). The weights can be written as: In the backward propagation procedure denoted by the brown interaction symbols, the memory elements evolve as: Thus, the weights are updated as follows: Equation (5) w  is given in Fig. 5g. These examples show the generality of the mechanical selflearning perceptron.

List of supplementary figures
Supplementary Figure 1. Computing process of the mechanical XNOR structure for input (1, 1). a Before receiving the time signal. b After receiving the time signal.

Supplementary Figure 4 Design of other structures required for computing. a
Structure that stores the bias. For (i), the bias is 0. For (ii), the bias is 1. b A variant design for the mechanical XNOR operation. c Design of the data selector. (i) shows the main components. (ii) is a sectional view of (i). (iii) (iv) Computing process of the data selector. For (iii), the output is In1 when c=0. For (iv), the output is In2 when c=1.